package net.ozgul.chordmaster;

import java.util.Arrays;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

public class ChordMaster extends Activity {
  
  private class TriadButtonTouchListener implements OnClickListener {

    public void onClick(View arg0) {
      Spinner s1 = (Spinner) findViewById(R.id.key_spinner);
      Spinner s2 = (Spinner) findViewById(R.id.chord_type_spinner);
      TextView t1 = (TextView) findViewById(R.id.triad_textview);
      
      Note note = (Note) s1.getSelectedItem();
      ScaleType scaleType = (ScaleType) s2.getSelectedItem();
      
      Scale scale = new Scale(note, scaleType);
      StringBuilder builder = new StringBuilder();
      for (Note n : scale.getSpelling()) {
        builder.append(n.toString() + ", ");
      }
      t1.setText(builder.toString());
    }

  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    setContentView(R.layout.main);

    ArrayAdapter<Note> adapter = new ArrayAdapter<Note>(
        this, android.R.layout.simple_spinner_item,
        Arrays.asList(Note.values()));
    
    ArrayAdapter<ScaleType> scaleTypeAdapter = new ArrayAdapter<ScaleType>(
            this, android.R.layout.simple_spinner_item,
            Arrays.asList(ScaleType.values()));
    
    // The key spinner
    Spinner s1 = (Spinner) findViewById(R.id.key_spinner);
    s1.setAdapter(adapter);
    
    // The chord type spinner
    Spinner s2 = (Spinner) findViewById(R.id.chord_type_spinner);
    s2.setAdapter(scaleTypeAdapter);
    
    // The button
    Button b1 = (Button) findViewById(R.id.triad_button);
    b1.setOnClickListener(new TriadButtonTouchListener());
  }
}
